package com.mpsc.mongodb.provide.config;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail myJobDetail() {
        return JobBuilder.newJob(HelloWorldJob.class)
                .withIdentity("HelloWorldJob", "HelloWorldJob")
                //JobDataMap可以给任务execute传递参数
                .usingJobData("arg1", "Hello")
                .usingJobData("arg2", "World")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger myTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(myJobDetail())
                .withIdentity("Hello World Job TRIGGER", "TRIGGER GROUP1")
                .usingJobData("arg11","TRIGGER-arg11")
                .usingJobData("arg1","TRIGGER-arg1")
                .startNow()
                //.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever())
                .withSchedule(CronScheduleBuilder.cronSchedule("0/10 * * * * ?"))
                .build();
    }
}
